!function(a) {
    a.fn.dragResize = function() {
        return a.quiui.run.call(this, "quiResizable", arguments, {
            idAttrName: "quiuiresizableid",
            hasElement: !1,
            propertyToElemnt: "target"
        });
    }, a.fn.quiGetResizableManager = function() {
        return a.quiui.run.call(this, "quiGetResizableManager", arguments, {
            idAttrName: "quiuiresizableid",
            hasElement: !1,
            propertyToElemnt: "target"
        });
    }, a.quiDefaults.Resizable = {
        handles: "n, e, s, w, ne, se, sw, nw",
        maxWidth: 2e3,
        maxHeight: 2e3,
        minWidth: 20,
        minHeight: 20,
        scope: 10,
        animate: !1,
        onStartResize: function() {},
        onResize: function() {},
        onStopResize: function() {},
        onEndResize: null
    }, a.quiui.controls.Resizable = function(b) {
        a.quiui.controls.Resizable.base.constructor.call(this, null, b);
    }, a.quiui.controls.Resizable.quiExtend(a.quiui.core.UIComponent, {
        __getType: function() {
            return "Resizable";
        },
        __idPrev: function() {
            return "Resizable";
        },
        _render: function() {
            var b = this, c = this.options;
            b.target = a(c.target), b.set(c), b.target.mousemove(function(d) {
                if (!c.disabled && (b.dir = b._getDir(d), b.dir ? b.target.css("cursor", b.dir + "-resize") : b.target.css("cursor").indexOf("-resize") > 0 && b.target.css("cursor", "default"), 
                c.target.quiuidragid)) {
                    var e = a.quiui.get(c.target.quiuidragid);
                    e && b.dir ? e.set("disabled", !0) : e && e.set("disabled", !1);
                }
            }).mousedown(function(a) {
                c.disabled || b.dir && b._start(a);
            });
        },
        _rendered: function() {
            this.options.target.quiuiresizableid = this.id;
        },
        _getDir: function(b) {
            var c = this, d = this.options, e = "", f = c.target.offset(), g = c.target.width(), h = c.target.height(), i = d.scope, j = b.pageX || b.screenX, k = b.pageY || b.screenY;
            return k >= f.top && k < f.top + i ? e += "n" : k <= f.top + h && k > f.top + h - i && (e += "s"), 
            j >= f.left && j < f.left + i ? e += "w" : j <= f.left + g && j > f.left + g - i && (e += "e"), 
            "all" == d.handles || "" == e ? e : -1 != a.inArray(e, c.handles) ? e : "";
        },
        _setHandles: function(a) {
            a && (this.handles = a.replace(/(\s*)/g, "").split(","));
        },
        _createProxy: function() {
            var b = this;
            b.proxy = a('<div class="l-resizable"></div>'), b.proxy.width(b.target.width()).height(b.target.height()), 
            b.proxy.attr("resizableid", b.id).appendTo("body");
        },
        _removeProxy: function() {
            var a = this;
            a.proxy && (a.proxy.remove(), a.proxy = null);
        },
        _start: function(b) {
            var c = this;
            this.options, c._createProxy(), c.proxy.css({
                left: c.target.offset().left,
                top: c.target.offset().top,
                position: "absolute"
            }), c.current = {
                dir: c.dir,
                left: c.target.offset().left,
                top: c.target.offset().top,
                startX: b.pageX || b.screenX,
                startY: b.pageY || b.clientY,
                width: c.target.width(),
                height: c.target.height()
            }, a(document).bind("selectstart.resizable", function() {
                return !1;
            }), a(document).bind("mouseup.resizable", function() {
                c._stop.apply(c, arguments);
            }), a(document).bind("mousemove.resizable", function() {
                c._drag.apply(c, arguments);
            }), c.proxy.show(), c.trigger("startResize", [ c.current, b ]);
        },
        changeBy: {
            t: [ "n", "ne", "nw" ],
            l: [ "w", "sw", "nw" ],
            w: [ "w", "sw", "nw", "e", "ne", "se" ],
            h: [ "n", "ne", "nw", "s", "se", "sw" ]
        },
        _drag: function(a) {
            var d, e, b = this;
            this.options, b.current && b.proxy && (b.proxy.css("cursor", "" == b.current.dir ? "default" : b.current.dir + "-resize"), 
            d = a.pageX || a.screenX, e = a.pageY || a.screenY, b.current.diffX = d - b.current.startX, 
            b.current.diffY = e - b.current.startY, b._applyResize(b.proxy), b.trigger("resize", [ b.current, a ]));
        },
        _stop: function(b) {
            var c = this;
            this.options, c.hasBind("stopResize") ? 0 != c.trigger("stopResize", [ c.current, b ]) && c._applyResize() : c._applyResize(), 
            c._removeProxy(), c.trigger("endResize", [ c.current, b ]), a(document).unbind("selectstart.resizable"), 
            a(document).unbind("mousemove.resizable"), a(document).unbind("mouseup.resizable");
        },
        _applyResize: function(b) {
            var c = this, d = this.options, e = {
                left: c.current.left,
                top: c.current.top,
                width: c.current.width,
                height: c.current.height
            }, f = !1;
            b || (b = c.target, f = !0, e.top = isNaN(parseInt(c.target.css("top"))) ? 0 : parseInt(c.target.css("top")), 
            e.left = isNaN(parseInt(c.target.css("left"))) ? 0 : parseInt(c.target.css("left"))), 
            a.inArray(c.current.dir, c.changeBy.l) > -1 ? (e.left += c.current.diffX, c.current.diffLeft = c.current.diffX) : f && delete e.left, 
            a.inArray(c.current.dir, c.changeBy.t) > -1 ? (e.top += c.current.diffY, c.current.diffTop = c.current.diffY) : f && delete e.top, 
            a.inArray(c.current.dir, c.changeBy.w) > -1 ? (e.width += (-1 == c.current.dir.indexOf("w") ? 1 : -1) * c.current.diffX, 
            c.current.newWidth = e.width) : f && delete e.width, a.inArray(c.current.dir, c.changeBy.h) > -1 ? (e.height += (-1 == c.current.dir.indexOf("n") ? 1 : -1) * c.current.diffY, 
            c.current.newHeight = e.height) : f && delete e.height, f && d.animate ? b.animate(e) : b.css(e);
        }
    });
}(jQuery);